package demo2;

import java.util.Arrays;

/**
 * Created with IntelliJ IDEA.
 * Description:
 * User: 87111
 * Date: 2025-09-06
 * Time: 18:40
 */
public class MyStack {
    public int[] elem;
    public int stackSize;

    public MyStack() {
        elem = new int[10];
    }

    //入栈
    public void push(int val) {
        if(isFull()) {
            elem = Arrays.copyOf(elem,2 * elem.length);
        }
        elem[stackSize] = val;
        stackSize++;
    }
    //出栈
    public int pop() {
        if(isEmpty()) {
            return -1;
        }
        stackSize--;
        return elem[stackSize-1];
    }
    //查看栈顶元素
    public int peek() {
        if(isEmpty()) {
            return -1;
        }
        return elem[stackSize-1];
    }
    //返回栈的真实元素数量
    public int size() {
        return stackSize;
    }
    //判断栈为空
    public boolean isEmpty() {
        return stackSize == 0;
    }
    //判断栈为满
    public boolean isFull() {
        return stackSize == elem.length;
    }
}
